package com.hardware.service.impl.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hardware.common.R;
import com.hardware.entity.system.Module;
import com.hardware.entity.system.Role;
import com.hardware.mapper.system.ModuleMapper;
import com.hardware.service.system.ModuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ModuleServiceImpl extends ServiceImpl<ModuleMapper,Module> implements ModuleService {
    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public R<Page> page(int page, int pageSize){
        //分页构造器
        Page<Module> pageInfo = new Page<>(page,pageSize);
        //条件构造器
        LambdaQueryWrapper<Module> queryWrapper = new LambdaQueryWrapper<>();
        //添加排序条件，根据sort进行排序
        queryWrapper.orderByAsc(Module::getOrderNo);
        //分页查询
        page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @Override
    public void delete(List<Long> ids) {
        //TODO 未做删除关联
        /*LambdaQueryWrapper<Role> dishLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //添加查询条件，根据分类id进行查询

        dishLambdaQueryWrapper.eq(Role::getCategoryId,id);
        int count = count(dishLambdaQueryWrapper);

        //查询当前分类是否关联了商品，如果已经关联，抛出一个业务异常
        if(count > 0){
            //已经关联商品，抛出一个业务异常
            throw new CustomException("当前分类下关联了商品，不能删除");
        }*/
        //正常删除分类
        removeByIds(ids);

    }
}
